package com.xj.api.bussiness.deviceInformationImg.web;

import com.xj.api.bussiness.deviceInformationImg.service.ITbDeviceInformationImgService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;


import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.baomidou.mybatisplus.plugins.Page;
import com.xj.api.base.web.BaseController;
import com.xj.common.base.common.bean.AbstractBean;
import com.xj.common.bussiness.deviceInformationImg.entity.TbDeviceInformationImg;

import io.swagger.annotations.ApiOperation;

import java.util.Date;
import java.util.List;

/**
 * <p>
 * 设备各种铭牌的照片  前端控制器
 * </p>
 *
 * @author Hmemb
 * @since 2018-03-16
 */
@RestController
@RequestMapping("deviceInformationImg")
public class TbDeviceInformationImgController extends BaseController{
	
	@Autowired
	private ITbDeviceInformationImgService deviceInformationImgService;
	
	@GetMapping
	@ApiOperation(value = "  列表", httpMethod = "GET", notes = "  列表")
	public AbstractBean deviceInformationImgList(@RequestParam(required=false,defaultValue="0") Integer pageNum,@RequestParam(required=false,defaultValue="10") Integer pageSize){
		return json(deviceInformationImgService.selectMapsPage(new Page<TbDeviceInformationImg>(pageNum, pageSize), new EntityWrapper<TbDeviceInformationImg>()));
	}
	
	@GetMapping("/{id}.auth")
	@ApiOperation(value = "  詳情", httpMethod = "GET", notes = "  詳情")
	public AbstractBean deviceInformationImgContent(@PathVariable Integer id){
		return json(deviceInformationImgService.selectById(id));
	}
	
	@PostMapping("save")
	@ApiOperation(value = "  新增", httpMethod = "POST", notes = " 新增")
	public AbstractBean add(TbDeviceInformationImg tbdeviceinformationimg){
		tbdeviceinformationimg.setCreateDate(new Date());
		if(!deviceInformationImgService.insertOrUpdate(tbdeviceinformationimg)){
			return error();
		}
		return success();
	}
	@DeleteMapping("{id}/delete")
	@ApiOperation(value = "  删除", httpMethod = "POST", notes = " 删除")
    public AbstractBean delete(@PathVariable(required=true) Integer id) {	
		if(!deviceInformationImgService.deleteById(id)){
		return error();
		}
		return success();
    }
	/*@GetMapping("{identityNum}/TbDeviceInformationImg")
	@ApiOperation(value = " 查询", httpMethod = "POST", notes = " 查询")
	public String getDeviceInformationImgByCondition(Map<String, Object> map, @PathVariable(required = true) String identityNum, TbDeviceInformationImg bean){
		System.out.print("***********************通过设备Id查找设备图片信息******************************");
		if(!identityNum.equals("") && identityNum !=null){
			List<TbDeviceInformationImg> deviceInformationImg = deviceInformationImgService.getDeviceInformationImgByCondition(bean);
			if(deviceInformationImg != null){
				map.put("record", deviceInformationImg);
				return "deviceInformationImg/form";
			}else{
				return "deviceInformationImg/list";
			}
		}else{
			return "deviceInformationImg/list";
		}
	}*/
	@PostMapping("TbDeviceInformationImg")
	@ApiOperation(value = " 根据数据库字段查询设备信息", httpMethod = "POST", notes = " 根据数据库字段查询设备信息")
	public AbstractBean getDeviceInformationImgByCondition(TbDeviceInformationImg tbDeviceInformationImg){
		List<TbDeviceInformationImg> list =deviceInformationImgService.getDeviceInformationImgByCondition(tbDeviceInformationImg);
		if (list != null && list.size()>0){
			return SuccessMessage("用户存在","1");
		}else {
			return fail("用户不存在","0");
		}
	}

	@PostMapping("getNewDeviceInformationImgEntity")
	@ApiOperation(value = " 根据设备铭牌照片表的对象查询最近更新的照片", httpMethod = "POST", notes = " 根据设备铭牌照片表的对象查询最近更新的照片")
	public AbstractBean getNewDeviceInformationImgEntity(TbDeviceInformationImg tbDeviceInformationImg){
		List<TbDeviceInformationImg> list =deviceInformationImgService.getNewDeviceInformationImgEntity(tbDeviceInformationImg);
		if (list != null && list.size()>0){
			return json(list);
		}else {
			return error();
		}
	}
}
